package coms.action;



import java.util.List;
import java.util.Map;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import  coms.datatransfer.ConferenceDTO;
import coms.ejb.sessionbean.ConferenceBeanRemote;
import coms.ejb.sessionbean.UserBeanRemote;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class BookedConferencesAction extends ActionSupport implements ModelDriven<ConferenceDTO> {

	
	private List<ConferenceDTO> listofCoferences;
	
	
	public String execute()
	{
		
		
		try {
			
			
			System.out.println("Hi I am in Booking ConferencesAction");
			
			HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
			Map<String,Object> session = ActionContext.getContext().getSession();
			
			ConferenceBeanRemote bean=lookupRemoteBean();
			
			listofCoferences= bean.findAllConferences();
			
			System.out.println("List of Conferences:"+listofCoferences.size());
			
			System.out.println("User ID is Session:"+session.get("userID"));
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			return "exception";
		}
		
		
		return "SUCCESS";
	}
	

	private ConferenceBeanRemote lookupRemoteBean() throws NamingException{
		InitialContext ctx = new InitialContext();
		
		System.out.println("In Look up method");
		return (ConferenceBeanRemote) ctx.lookup("java:app/coms-ejb/ConferenceBean!coms.ejb.sessionbean.ConferenceBeanRemote");
	
	
	}
	
	

	public List<ConferenceDTO> getListofCoferences() {
		return listofCoferences;
	}


	public void setListofCoferences(List<ConferenceDTO> listofCoferences) {
		this.listofCoferences = listofCoferences;
	}


	@Override
	public ConferenceDTO getModel() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	
	
	

}
